/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import vo.VOInstitution;

/**
 *
 * @author santiagobaldrich
 */
@Entity
@Table(name = "Institution")
@NamedQueries(
{
    @NamedQuery(name = "Institution.findAll", query = "SELECT i FROM Institution i"),
    @NamedQuery(name = "Institution.findByIdInstitution", query = "SELECT i FROM Institution i WHERE i.idInstitution = :idInstitution"),
    @NamedQuery(name = "Institution.findByName", query = "SELECT i FROM Institution i WHERE i.name = :name"),
    @NamedQuery(name = "Institution.findByIsHighSchool", query = "SELECT i FROM Institution i WHERE i.isHighSchool = :isHighSchool")
})
public class Institution implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idInstitution")
    private Integer idInstitution;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "isHighSchool")
    private boolean isHighSchool;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "institution")
    private Collection<User> userCollection;
    @JoinColumn(name = "idCountry", referencedColumnName = "idCountry")
    @ManyToOne(optional = false)
    private Country country;

    public Institution()
    {
    }

    public Institution(Integer idInstitution)
    {
        this.idInstitution = idInstitution;
    }

    public Institution(Integer idInstitution, String name, boolean isHighSchool)
    {
        this.idInstitution = idInstitution;
        this.name = name;
        this.isHighSchool = isHighSchool;
    }

    public Integer getIdInstitution()
    {
        return idInstitution;
    }

    public void setIdInstitution(Integer idInstitution)
    {
        this.idInstitution = idInstitution;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public boolean getIsHighSchool()
    {
        return isHighSchool;
    }

    public void setIsHighSchool(boolean isHighSchool)
    {
        this.isHighSchool = isHighSchool;
    }

    public Collection<User> getUserCollection()
    {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection)
    {
        this.userCollection = userCollection;
    }

    public Country getCountry()
    {
        return country;
    }

    public void setCountry(Country country)
    {
        this.country = country;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idInstitution != null ? idInstitution.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Institution))
        {
            return false;
        }
        Institution other = (Institution) object;
        if ((this.idInstitution == null && other.idInstitution != null) || (this.idInstitution != null && !this.idInstitution.equals(other.idInstitution)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Institution[idInstitution=" + idInstitution + "]";
    }
    public VOInstitution getVO()
    {
        VOInstitution vo = new VOInstitution();
        vo.setCountryName(country.getName());
        vo.setIdInstitution(idInstitution);
        vo.setIsHighSchool(isHighSchool);
        vo.setName(name);
        return vo;
    }
}
